package two.chapter_1.c1_4;

import java.util.Arrays;

public class EqaulNumberFinder {

    /**
     * 增长数量级  N^2
     *
     * @param a
     * @return
     */
    public static int find(int a[]) {
        int count = 0;
        for (int i = 0; i < a.length; i++) {
            for (int j = i + 1; j < a.length; j++) {
                if (a[i] == a[j]) {
                    count++;
                }
            }
        }
        return count;
    }
    /**
     * 增长数量级  NlogN
     * @param a
     * @return
     */
    public static int findFast(int a[]) {
        int count = 0;
        Arrays.sort(a);//NlogN
        for (int i = 0; i < a.length; i++) {
            int j = i + 1;
            while (BinarySearch.rank(a[i], j, a.length - 1, a) != -1) {
                j++;
                count++;
            }
        }

        return count;
    }

}
